#include <QtCore>
#include <QtGui>
#include <QtWebKit>

class T_Web : public QWebView
{
    Q_OBJECT
public:
    explicit T_Web() {
        //this->resize(200,200);
        this->resize(200,150);
        this->setHtml(
                "<body style='margin:0;padding:0'>"
                "<table border='1' width='100%' height='100%'><tr><td>"
                "<div　style='background:blue;'>"
                "<img src='qrc:/default.jpg' />"
                //"<br />"
                "</td><td>"
                "<button onclick='webview.add2(11,22)'>ボタン1</button>"
                "</div>"
                "</td></tr></table>"
                "</body>"
                );
        connect(this->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
                this, SLOT(populateJavaScriptWindowObject()));
    }
    virtual ~T_Web() {
    }
protected slots:
    void populateJavaScriptWindowObject()
    {
        this->page()->mainFrame()->addToJavaScriptWindowObject("webview", this);
    }
public slots:
    int add2(int x, int y)
    {
        qDebug() << "[x, y]" << x << y;
        return x+y;
    }
};

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));

    //T_Widget *v_widget = new T_Widget;
    //T_Web *v_web = new T_Web;

    QTableWidget v_tableWidget;
    v_tableWidget.setSelectionMode(QAbstractItemView::NoSelection);
    v_tableWidget.setColumnCount(2);
    v_tableWidget.setRowCount(600);

    v_tableWidget.verticalHeader()->setUpdatesEnabled(FALSE);
    for (int i = 0; i < v_tableWidget.rowCount(); i++)
    {
        T_Web *v_web = new T_Web;
        v_tableWidget.setCellWidget(i, 0, v_web);
        v_tableWidget.verticalHeader()->resizeSection(i, v_web->height());
    }
    v_tableWidget.verticalHeader()->setUpdatesEnabled(TRUE);

    v_tableWidget.horizontalHeader()->resizeSection(0, 400);


    v_tableWidget.resize(640, 480);
    v_tableWidget.show();


    return app.exec();
}

#include "main.moc"
